package com.example.understand_compose1.testcase_compose.page

import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.example.understand_compose1.R

// 请在ui.theme查找你自己定义的theme

//class MessageFet : PreviewParameterProvider<Message> {
//    override val values: Sequence<Message> = sequenceOf(Message("feature 1", "get it"), Message("kello", "world"))
//}
//
//@Preview
//@Composable
//fun PreviewMessageCardByTheme(
//   @PreviewParameter(MessageFet::class) msg: Message
//) {
////    MaterialTheme { // Your Own theme
////        Surface {
////            MessageCardByLayout(
////                msg = Message("Lexi", "Take a look at Jetpack Compose")
////            )
////        }
////    }
//
//    Row(modifier = Modifier.padding(all = 8.dp)) {
//        Image(
//            painter = painterResource(R.drawable.ic_launcher_background),
//            contentDescription = null,
//            modifier = Modifier
//                .size(40.dp)
//                .clip(CircleShape)
//                .border(1.5.dp, MaterialTheme.colorScheme.primary, CircleShape)
//        )
//
//        Spacer(modifier = Modifier.width(8.dp))
//
//        Column {
//            Text(
//                text = msg.author,
//                color = MaterialTheme.colorScheme.secondary
//            )
//
//            Spacer(modifier = Modifier.height(4.dp))
//
//            Text(text = msg.body)
//        }
//    }
//}

// TODO: this example failed

data class Message(val author: String, val body: String)

class MessageFet : PreviewParameterProvider<Message> {
    override val values: Sequence<Message> = sequenceOf(Message("feature 1", "get it"), Message("kello", "world"))
}

@Preview
@Composable
fun PreviewMessageCardByTheme(
    @PreviewParameter(MessageFet::class) msg: Message
) {
    Row(modifier = Modifier.padding(all = 8.dp)) {
        Image(
            painter = painterResource(R.drawable.ic_launcher_background),
            contentDescription = null,
            modifier = Modifier
                .size(40.dp)
                .clip(CircleShape)
                .border(1.5.dp, MaterialTheme.colorScheme.primary, CircleShape)
        )

        Spacer(modifier = Modifier.width(8.dp))

        Column {
            Text(
                text = msg.author,
                color = MaterialTheme.colorScheme.secondary
            )

            Spacer(modifier = Modifier.height(4.dp))

            Text(text = msg.body)
        }
    }
}